package cn.johnyu.util;

import cn.johnyu.domain.Account;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.List;

public class GsonUtil {
    public static String accountToJson(Account account){
        Gson gson = new GsonBuilder()
                .create();
       return gson.toJson(account);
    }
    public static Account jsonToAccount(String json){
        Gson gson = new GsonBuilder()
                .create();
        return gson.fromJson(json, Account.class);
    }

    public static void main(String[] args) {
        String s = accountToJson(new Account("1", "John", "password", List.of("ROLE_ADMIN", "ROLE_USER")));
        System.out.println(s);
        Account account = jsonToAccount(s);
        System.out.println(account);
    }
}
